﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/EmptyStyle.Master"
    Inherits="System.Web.Mvc.ViewPage<System.IO.DirectoryInfo>" %>

<asp:Content ID="headerConter" runat="server" ContentPlaceHolderID="HeadContent">
    <link href="/Scripts/treeView/jquery.treeview.css" rel="stylesheet" type="text/css" />

    <script src="/Scripts/treeView/jquery.treeview.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            $("#folderTree").treeview({ persist: "location",
                collapsed: true,
                unique: true
            });
            $("a", $("#folderTree")).click(function() {
                var url = '<%=Url.Action("Files")%>';
                $.post(url, { directory: $(this).attr("href").substr(1), filter: "*.gif|*.png|*.jpg|*.jpeg" }, function(e) {
                    $("#files").children().remove();
                    $(e).each(function() {
                        var name = this.substr(this.lastIndexOf("/") + 1);
                        $("#files").append("<li class='ui-corner-all'><a><div><img src='" + this + "'/></div>" + name + "<a></li>");
                    });
                });
                return false;
            });
        });
    </script>

    <style type="text/css">
        #files li
        {
            float: left;
            margin: 5px;
            border: solid 1px #ccc;
        }
    </style>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/C#" runat="server">
        private void Render(System.IO.DirectoryInfo parent, string parentPath)
        {
            foreach (var child in parent.GetDirectories())
            {
                Response.Write("<ul>");
                Response.Write("<li><a href='#" + Url.Encode(parentPath + "/" + child.Name) + "'>" + child.Name + "</a>");
                if (child.GetDirectories().Length != 0)
                {
                    Response.Write("<ul>");
                    this.Render(child, parentPath + "/" + child.Name);
                    Response.Write("</ul>");
                }
                Response.Write("</li></ul>");
            }

        }
    </script>

    <div class="mainContentWrapper">
        <div class="rightMainContent">
            文件
            <ul id="files">
            </ul>
        </div>
    </div>
    <div class="leftMenu">
        <ul id="folderTree">
            <li><a href="#<%= Url.Encode(ViewData["Parent"].ToString())%>">
                <%=this.Model.Name%></a>
                <%                                  
                    this.Render(this.Model, ViewData["Parent"].ToString());
                %>
            </li>
        </ul>
    </div>
    <div style="clear: both">
    </div>
</asp:Content>
